package com.d3works.apps.base.web;

import com.d3works.apps.account.db.PaymentMode;
import com.d3works.apps.base.db.Company;
import com.d3works.apps.base.db.Partner;
import com.d3works.apps.base.service.BankDetailsServiceImpl;
import com.d3works.exception.D3worksException;
import com.d3works.inject.Beans;
import com.d3works.rpc.ActionRequest;
import com.d3works.rpc.ActionResponse;
import com.google.inject.Singleton;

/** Controller called from multiple forms, */
@Singleton
public class CompanyBankDetailsController {

  /**
   * Set the domain of company bank details field
   *
   * @param request
   * @param response
   * @throws D3worksException
   */
  public void fillCompanyBankDetailsDomain(ActionRequest request, ActionResponse response)
      throws D3worksException {
    Partner partner = (Partner) request.getContext().get("partner");
    Company company = (Company) request.getContext().get("company");
    PaymentMode paymentMode = (PaymentMode) request.getContext().get("paymentMode");
    Integer operationTypeSelect = null;
    if (request.getContext().get("_operationTypeSelect") != null) {
      operationTypeSelect =
          Integer.valueOf(request.getContext().get("_operationTypeSelect").toString());
    }
    response.setAttr(
        "companyBankDetails",
        "domain",
        Beans.get(BankDetailsServiceImpl.class)
            .createCompanyBankDetailsDomain(partner, company, paymentMode, operationTypeSelect));
  }
}
